import WidgetDefinition, { WidgetDefinitionOptions } from '@/core/model/WidgetDefinition'
import { Component, Vue } from 'vue-property-decorator'

@Component
export default class WidgetDefinitionMixins extends Vue {
  public widgetDefinitions: WidgetDefinition[] = []

  public widgetDefinitionGroups: { name: string; displayName: string }[] = []

  public isWidgetTag(tag: string) {
    return this.widgetDefinitions.findIndex((d) => d.tag === tag) !== -1
  }

  public getWidgetDefinitionBytag(tag: string) {
    return this.widgetDefinitions.find((d) => d.tag === tag)
  }

  public registerWidgetGroup(name: string, displayName: string ) {
    this.widgetDefinitionGroups.push({ name, displayName })
  }

  public registerWidget(widgetDefinitionOptions: WidgetDefinitionOptions) {
    this.widgetDefinitions.push(new WidgetDefinition(widgetDefinitionOptions))
  }

  public getWidgetComponent(tag: string) {
    return this.widgetDefinitions.find(d => d.tag === tag)?.component
  }
}